var http = require('http');
var fs = require('fs');
var nodegrass = require('nodegrass');
var baseDir = '/home/looop/workspace/malldetail/assets/4.0b';
var i=0;
var f = 0;
var resultMap = {};
function testAssets(filePath){
	fs.stat(filePath, function(err, stat){
		if(err){
			console.log(require('util').inspect(err))
			return;
		}
		if(stat.isDirectory()){
			fs.readdir(filePath, function(err, files){
				for(var i=0; i < files.length; i++){
					testAssets(filePath + '/' + files[i]);
				}
			})
		}else{
			f++;
			new function(){
				var url = 'http://l.tbcdn.cn/apps/malldetail' + filePath.substring(39, filePath.length);
				resultMap[url] = 'sended';
//				console.log('\'' + url + '\' ,')
				nodegrass.get(url, function(data, status, headers){
					resultMap[url] = 'backed';
					i++;
					console.log(i + '	' + url + '      ' + status)
					
					if(status + '' != '200'){
						console.log('error! url:' + url + 'response status code: ' + res.statusCode)
					}
				})
			}();
		}
	})
}

http.createServer(function(req, res){
	for(var key in resultMap){
		res.write(key + ':' + resultMap[key] + '\n');
	}
	res.end()
}).listen(10000, '127.0.0.1');

testAssets(baseDir)

